﻿<cfsilent>
	<cfscript>

		jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		
		response = structNew();
		structInsert(response, "success", false, true);
		
		examId = event.getArg("EXID");
		
		weekDay = event.getArg("wkday");
		lectureId = event.getArg("lec");
		
		
		transaction {
			
			/* 加载考试任务 */
		
			/* 考试场次 */
	
			/* 保存考试时间安排 */

			/* 更新排考进度 */
	
			ExamWeekDay = weekDay ;
			ExamCell = lectureId ;
			TaskProgress = "1";
			
			sql = "UPDATE t_resittask a 
					SET a.wdidx = :ExamWeekDay ,
						a.cellidx = :ExamCell ,
						a.task_prog = :TaskProgress 
					WHERE a.task_exrstid = :examId ";
			
			queryObj = new Query( datasource=application.dnsMaster);
			queryObj.addParam( name="ExamWeekDay", value=ExamWeekDay, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="ExamCell", value=ExamCell, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="TaskProgress", value=TaskProgress, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="examId", value=examId, cfsqltype="cf_sql_char" );
			queryObj.execute( sql=sql );
			
			/* 数据密闭 */
			
			/* 如果已经保存了学生考试安排 则全部删除 */
	
			sql = "DELETE 
					FROM t_student_resit a 
					WHERE a.task_exrstid = :examId ";
					
			queryObj = new Query( datasource=application.dnsMaster);
			queryObj.addParam( name="examId", value=examId, cfsqltype="cf_sql_char" );
			queryObj.execute( sql=sql );
							
			/* 如果已经保存了场地占用 则全部删除 */
		
			sql = "DELETE 
					FROM t_clsroom_timetable a 
					WHERE a.crtime_id IN (
						  SELECT b.crtime_id 
						  FROM t_clsroom_forresit b 
						  WHERE b.task_exrstid = :examId 
					) ";
					
			queryObj = new Query( datasource=application.dnsMaster);
			queryObj.addParam( name="examId", value=examId, cfsqltype="cf_sql_char" );
			queryObj.execute( sql=sql );

			structInsert(response, "ExamID", examId, true);
			structInsert(response, "weekDay", weekDay, true);
			structInsert(response, "lecture", lectureId, true);
			
			structInsert(response, "success", true, true);
						
		}

	</cfscript>
</cfsilent><cfoutput>#jsonAdvice.encode(data:response, stringNumbers:true)#</cfoutput>